package com.wanxi.servlet;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.service.ProductService;
import com.wanxi.service.impl.ProductServiceImpl;
import com.wanxi.util.Tool;
import com.wanxi.vo.ProductVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getCountForProductPage")
public class ProductGetCountServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String cuisineId = req.getParameter("cuisineId");
        ProductVo productVo = new ProductVo();
        productVo.setCuisineId(Tool.strToInt(cuisineId));


        ProductService productService = new ProductServiceImpl();
        int count=productService.findProductCountByCuisineId(productVo);
        resp.getWriter().println(JSONObject.toJSONString(count));
    }
}
